#!/usr/bin/env python
# -*- coding: utf8 -*-
# title       :
# description :
# author      :'ShenMeng'

import maya.cmds as cmds
import functools  
import os
from batchmanager.core.verbatchmanager import Tasker

def batcher(batchType, subType='all'):
    def wrapper(func):
        @functools.wraps(func)
        def _wrapper(*args, **kwargs):
            try:
                scene_file = cmds.file(q=1, sn=1)
                root_path = os.path.dirname(scene_file).replace('\\', '/')
                scene_name = os.path.basename(scene_file)
                tasker = Tasker(batchType, root_path, subType)
                data = {scene_name:{"user":tasker.id, "time":tasker.getTime(), "info":''}}
                ret = func(loggle=tasker.loggle, data=data, *args, **kwargs)
                return ret
            except Exception, e:
                print e
            finally:
                cmds.scriptJob(ie="cmds.quit(f=1)")
        return _wrapper
    return wrapper
